fix(ssl): enforce TLS 1.2 minimum in get_certificate#117
Open
ajshedivy wants to merge 1 commit into
Open
Conversation
CodeQL py/insecure-protocol (CWE-327) flagged the SSLContext used in get_certificate() because it did not explicitly forbid the broken TLSv1/TLSv1.1 protocols before wrapping the socket. Set context.minimum_version = ssl.TLSVersion.TLSv1_2 so only TLS 1.2+ is negotiated, per the alert's recommended remediation. Resolves code scanning alert #2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves code scanning alert #2 —
py/insecure-protocol: Use of insecure SSL/TLS version (CWE-327, severity: high).CodeQL flagged the
SSLContextcreated inget_certificate()(mapepire_python/ssl.py) because it was used to wrap a socket without explicitly forbidding the broken TLSv1 and TLSv1.1 protocols. Whilessl.create_default_context()sets a sane floor on modern CPython, the static analyzer (correctly, as defense-in-depth) wants the minimum version pinned so the guarantee is explicit and independent of the runtime's defaults.Change
A single line, exactly the remediation recommended in the alert's help text:
This pins the negotiated protocol floor to TLS 1.2, so TLS 1.0/1.1 (and all SSL versions) are rejected during the handshake.
Verification
python -m py_compile mapepire_python/ssl.py— compiles cleanly.context.minimum_version == ssl.TLSVersion.TLSv1_2(771) and that bothTLSVersion.TLSv1andTLSVersion.TLSv1_1fall below the enforced minimum.ssl.TLSVersionis available on all supported runtimes (Python ≥ 3.10; added in 3.7).Notes
get_certificate()context is changed._create_ssl_context()inwebsocket.pyuses the samecreate_default_context()helper but was not flagged (its context is handed to thewebsocketslibrary rather than a directwrap_socketsink). Pinning the minimum version there too would be a reasonable defense-in-depth follow-up if desired.